/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package answerquestion_simple;
import jess.*;
/**
 *
 * @author Huynh Ngoc Khue
 */
public class JessRuleDeftemplate {
    Rete RETE_ENGINER;
    
    public JessRuleDeftemplate()
    {
        this.RETE_ENGINER = new Rete();
        
    }
    public void MakeRule(){
        try{

           // when,where => advmod
            this.RETE_ENGINER.eval("(defrule Search1 "
                   + "?prep_V <-(prep{Pattern == 1}) "
                   + "?advmod_V <-(advmod{Pattern == 0 && Head == prep_V.Head}) "
                   + "(pobj{Head == prep_V.Dependence && Pattern == 1}(Dependence ?value))"
                   + "=>(printout t ?value crlf))");

            // what : dobj
            this.RETE_ENGINER.eval("(defrule Search2"
                    + " ?dobj_V <- (dobj{Pattern == 0 && Dependence == \"What\"})"
                    + "(dobj{Pattern == 1 && Head == dobj_V.Head && Dependence != dobj_V.Dependence}(Dependence ?value))"
                    + "=>(printout t ?value crlf))");
            // who : nsubj
            this.RETE_ENGINER.eval("(defrule Search3"
                    + " ?nsubj_V <- (nsubj{(Pattern == 0) &&(Dependence == \"Who\")})"
                    + " ?temp <-(nsubj{Pattern == 1 && Head == nsubj_V.Head&& Dependence != nsubj_V.Dependence}(Dependence ?value))"
                    + "=>(printout t ?value crlf))");
            // what do[es] ... do ? question.
            // Case 1: answer verb
           this.RETE_ENGINER.eval("(defrule Search4"
                    + " ?a <-(dobj{Pattern == 0 && Head == \"do\" && Dependence == \"What\"})"
                    + "(aux{(Head == \"do\")&&(Dependence == \"does\"||Dependence == \"do\")&& (Pattern == 0)})"
                    + " ?nsubj <- (nsubj{Pattern == 1})"
                    + " =>(printout t ?nsubj.Head ?dobj.Dependence crlf))");
           // Case 2: answer verb + direct object
           this.RETE_ENGINER.eval("(defrule Search5"
                    + " ?a <-(dobj{Pattern == 0 && Head == \"do\" && Dependence == \"What\"})"
                    + "(aux{(Head == \"do\")&&(Dependence == \"does\"||Dependence == \"do\")&& (Pattern == 0)})"
                    + " ?dobj <- (dobj{Pattern == 1})"
                    + " ?nsubj <- (nsubj{Pattern == 1})"
                    + " =>(printout t ?nsubj.Head ?dobj.Dependence crlf))");
        }
        catch(Exception e)
        {
            System.out.println("Error in makerule function\n" + e.toString());
        }
    }

    public void MakeTemplate(){
        try{

            // relation 1
            Deftemplate def_abbrev = new Deftemplate("abbrev","Abbreviation modifier",this.RETE_ENGINER);
            def_abbrev.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_abbrev.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_abbrev.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_abbrev);

            // relation 2
            Deftemplate def_acomp = new Deftemplate("acomp"," Adjectival complement",this.RETE_ENGINER);
            def_acomp.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_acomp.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_acomp.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_acomp);

            // relation 3
            Deftemplate def_advcl = new Deftemplate("advcl","Adverbial clause",this.RETE_ENGINER);
            def_advcl.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_advcl.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_advcl.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_advcl);

            // relation 4
            Deftemplate def_advmod = new Deftemplate("advmod","Adverbial modifier",this.RETE_ENGINER);
            def_advmod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_advmod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_advmod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_advmod);

            // relation 5
            Deftemplate def_agent = new Deftemplate("agent","Agent",this.RETE_ENGINER);
            def_agent.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_agent.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_agent.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_agent);

            // relation 6
            Deftemplate def_amod = new Deftemplate("amod","Adjectival modifier",this.RETE_ENGINER);
            def_amod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_amod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_amod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_amod);

            // relation 7
            Deftemplate def_appos = new Deftemplate("appos","Adjectival modifier",this.RETE_ENGINER);
            def_appos.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_appos.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_appos.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_appos);

            // relation 8
            Deftemplate def_attr = new Deftemplate("attr","Attribute",this.RETE_ENGINER);
            def_attr.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_attr.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_attr.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_attr);

            // relation  9
            Deftemplate def_aux = new Deftemplate("aux","Auxiliary",this.RETE_ENGINER);
            def_aux.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_aux.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_aux.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_aux);

            // relation 10
            Deftemplate def_auxpass = new Deftemplate("auxpass","Passive auxiliary",this.RETE_ENGINER);
            def_auxpass.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_auxpass.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_auxpass.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_auxpass);

            // relation 11
            Deftemplate def_cc = new Deftemplate("cc","Coordination",this.RETE_ENGINER);
            def_cc.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_cc.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_cc.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_cc);

            // relation 12
            Deftemplate def_ccomp = new Deftemplate("ccomp","Clausal complement",this.RETE_ENGINER);
            def_ccomp.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_ccomp.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_ccomp.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_ccomp);

            // relation 13
            Deftemplate def_complm = new Deftemplate("complm","Complementizer",this.RETE_ENGINER);
            def_complm.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_complm.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_complm.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_complm);

            // relation 14
            Deftemplate def_conj = new Deftemplate("conj","Conjunct",this.RETE_ENGINER);
            def_conj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_conj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_conj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");

            // relation 15
            Deftemplate def_cop = new Deftemplate("cop","Copula",this.RETE_ENGINER);
            def_cop.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_cop.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_cop.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_cop);

            // relation 16
            Deftemplate def_csubj = new Deftemplate("csubj","clausal subject",this.RETE_ENGINER);
            def_csubj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_csubj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_csubj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_csubj);

            // relation 17
            Deftemplate def_csubjpass = new Deftemplate("csubjpass","clausal passive sbuject",this.RETE_ENGINER);
            def_csubjpass.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_csubjpass.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_csubjpass.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_csubjpass);

            // relation 18
            Deftemplate def_det = new Deftemplate("det","Determiner",this.RETE_ENGINER);
            def_det.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_det.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_det.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_det);

            // relation 19
            Deftemplate def_dobj = new Deftemplate("dobj","Direct Object",this.RETE_ENGINER);
            def_dobj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_dobj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_dobj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_dobj);

            // relation 20
            Deftemplate def_expl = new Deftemplate("expl","Expletive",this.RETE_ENGINER);
            def_expl.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_expl.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_expl.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_expl);

            // relation 21
            Deftemplate def_infmod = new Deftemplate("infmod","Adjectival modifier",this.RETE_ENGINER);
            def_infmod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_infmod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_infmod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_infmod);

            // relation 22
            Deftemplate def_iobj = new Deftemplate("iobj","Indirect object",this.RETE_ENGINER);
            def_iobj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_iobj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_iobj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_iobj);

            // relation 25
            Deftemplate def_neg = new Deftemplate("neg","Negation modifier",this.RETE_ENGINER);
            def_neg.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_neg.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_neg.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_neg);

            // relation 26
            Deftemplate def_nn = new Deftemplate("nn","Noun compound modifier",this.RETE_ENGINER);
            def_nn.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_nn.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_nn.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_nn);

            // nsubj 27
            Deftemplate def_nsubj = new Deftemplate("nsubj","nominal subject",this.RETE_ENGINER);
            def_nsubj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_nsubj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_nsubj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_nsubj);

            // relation 28
            Deftemplate def_nsubjpass = new Deftemplate("nsubjpass","passive nominal subject",this.RETE_ENGINER);
            def_nsubjpass.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_nsubjpass.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_nsubjpass.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_nsubjpass);

            // relation 29
            Deftemplate def_num = new Deftemplate("num","numeric modifier",this.RETE_ENGINER);
            def_num.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_num.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_num.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_num);

            // relation 30
            Deftemplate def_number = new Deftemplate("number","element of compound number",this.RETE_ENGINER);
            def_number.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_number.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_number.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_number);

            // relation 31
            Deftemplate def_pastmod = new Deftemplate("pastmod","Participial modifier",this.RETE_ENGINER);
            def_pastmod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_pastmod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_pastmod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_pastmod);

            // relation 32
            Deftemplate def_pcomp = new Deftemplate("pcomp","Preopositional complement",this.RETE_ENGINER);
            def_pcomp.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_pcomp.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_pcomp.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_pcomp);

            // relation 33
            Deftemplate def_pobj = new Deftemplate("pobj","Object of a preposition",this.RETE_ENGINER);
            def_pobj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_pobj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_pobj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_pobj);

            // relation 34
            Deftemplate def_poss = new Deftemplate("poss","Possession modifier",this.RETE_ENGINER);
            def_poss.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_poss.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_poss.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_poss);

            // relation 35
            Deftemplate def_possessive = new Deftemplate("possessive","Possessive modifier",this.RETE_ENGINER);
            def_possessive.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_possessive.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_possessive.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_possessive);

            // relation 36
            Deftemplate def_preconj = new Deftemplate("preconj","Preconjunct modifier",this.RETE_ENGINER);
            def_preconj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_preconj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_preconj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_preconj);

            // relation 37
            Deftemplate def_predet = new Deftemplate("predet","Predeterminor",this.RETE_ENGINER);
            def_predet.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_predet.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_predet.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_predet);

            // relation 38
            Deftemplate def_prep = new Deftemplate("prep","Propositional modifier",this.RETE_ENGINER);
            def_prep.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_prep.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_prep.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_prep);

            // relation 39
            Deftemplate def_prepc = new Deftemplate("prepc","Prepostional clausal modifier",this.RETE_ENGINER);
            def_prepc.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_prepc.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_prepc.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_prepc);

            // relation 40
            Deftemplate def_ptr = new Deftemplate("ptr","phrasal verb particle",this.RETE_ENGINER);
            def_ptr.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_ptr.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_ptr.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_ptr);

            // relation 41
            Deftemplate def_punct = new Deftemplate("punct","punctuation",this.RETE_ENGINER);
            def_punct.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_punct.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_punct.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_punct);

            // relation 42
            Deftemplate def_purpcl = new Deftemplate("purpcl","Porpose clause modifier",this.RETE_ENGINER);
            def_purpcl.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_purpcl.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_purpcl.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_purpcl);

            // relation 43
            Deftemplate def_quantmod = new Deftemplate("quantmod","Qautifier phrase modifier",this.RETE_ENGINER);
            def_amod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_amod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_amod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_amod);

            // relation 44
            Deftemplate def_rcmod = new Deftemplate("rcmod","Relative clause modifier",this.RETE_ENGINER);
            def_rcmod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_rcmod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_rcmod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_rcmod);

            // relation 45
            Deftemplate def_ref = new Deftemplate("ref","Referent",this.RETE_ENGINER);
            def_ref.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_ref.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_ref.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_ref);

            // relation 46
            Deftemplate def_rel = new Deftemplate("rel","Relative ",this.RETE_ENGINER);
            def_rel.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_rel.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_rel.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_rel);

            // relation 47
            Deftemplate def_tmod = new Deftemplate("tmod","Temporal modifier",this.RETE_ENGINER);
            def_tmod.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_tmod.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_tmod.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_tmod);


            // relation 48
            Deftemplate def_xcomp = new Deftemplate("xcomp","Open clausal complement",this.RETE_ENGINER);
            def_xcomp.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_xcomp.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_xcomp.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_xcomp);
            // relation 49
            Deftemplate def_xsubj = new Deftemplate("xsubj","Controlling subject",this.RETE_ENGINER);
            def_xsubj.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_xsubj.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_xsubj.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_xsubj);

            // relation dependent
            Deftemplate def_dep = new Deftemplate("dep","Controlling subject",this.RETE_ENGINER);
            def_dep.addSlot("Head",new Value("",RU.STRING), "STRING");
            def_dep.addSlot("Dependence",new Value("",RU.STRING), "STRING");
            def_dep.addSlot("Pattern", new Value(0,RU.INTEGER), "NUMBER");
            this.RETE_ENGINER.addDeftemplate(def_dep);
        }
        catch(Exception e)
        {
            System.out.println("error in makeTemplate function"+e.toString());
        }

    }

    public Rete getRete_Engine()
    {
        return this.RETE_ENGINER;
    }
}
